########################################################################################################################################################
# July 14 2020
# Replication File
# Rebecca Cordell, Thorin M. Wright, Paul F. Diehl
# Extant Commitment, Risk, and UN Peacekeeping Authorization
# International Interactions
# https://www.tandfonline.com/toc/gini20/current 
########################################################################################################################################################

# Reset work environment
rm(list=ls())

# Required packages
#install.packages("stargazer")
#install.packages("pscl")
#install.packages("lmtest")
#install.packages("ggplot2")
#install.packages("dplyr")
#install.packages("e1071")

require("stargazer")
require("pscl")
require("lmtest")
require("ggplot2")
require("dplyr")
require("e1071")
options(scipen=999)

###############
# Read in Data
###############

pk_data <- read.csv("CordellWrightDiehl_2020_ExtantCommitment.csv") 

#########################################################################
# Table 1: Logistic Regression, UN authorization of peacekeeping mission
#########################################################################

# Model 1: Independent Variables Only, DV = UN PK Mission Authorized
tab.1.m1 <- glm(un.pk.mission~un.pk.operations.t_1+ un.pk.personnel.t_1+ un.pk.budget.t_1+ un.pk.fatalities.t_1+ peace.agreement.t_1,data=pk_data,family=binomial)

# Model 2: Independent and Control Variables, DV = UN PK Mission Authorized
tab.1.m2 <- glm(un.pk.mission~un.pk.operations.t_1+ un.pk.personnel.t_1+ un.pk.budget.t_1+ un.pk.fatalities.t_1+ peace.agreement.t_1+ civil.conflict.year+ total.civil.conflicts+ previous.un.pk.operation + civilian.casualties.log+ battle.deaths.log+ population.log+armed.forces.log+democracy+p5.alliance,data=pk_data,family=binomial)
stargazer(tab.1.m1, tab.1.m2, type = "text")

# Pseudo R2: McFadden
round(pR2(tab.1.m1), digits=3)
round(pR2(tab.1.m2), digits=3)

# LR chi2 and Prob>chi2 
round(lrtest(tab.1.m1), digits=3)
round(lrtest(tab.1.m2), digits=3)

#################################################################
# Results - In Text Quotations
#################################################################

# "Indeed, in our sample, annual figures on UN peacekeeping fatalities are positively correlated with annual global estimates of civilian casualties (r=.36) and UN peacekeeping personnel numbers (r=.61) respectively."
pk_data_year<-pk_data[c("year","un.pk.fatalities.t_1","un.pk.personnel.t_1","civilian.casualties")]
pk_data_year<-pk_data_year %>%
  group_by(year) %>% 
  summarise_each(sum)
pk_data_year_t<-pk_data_year[2:28, 1:3]
pk_data_year_t$year<-pk_data_year_t$year-1
colnames(pk_data_year)
civilian.casualties<-pk_data_year[1:27, 4]
pk_data_year_t<-cbind(pk_data_year_t,civilian.casualties)

round(cor(pk_data_year_t$un.pk.fatalities.t_1, pk_data_year_t$civilian.casualties, method="pearson", use = "complete.obs"), digits=2)
round(cor(pk_data_year_t$un.pk.fatalities.t_1, pk_data_year_t$un.pk.personnel.t_1, method="pearson", use = "complete.obs"), digits=2)

# "We also compute the natural logarithm for the UN PK Budget (t-1) and UN PK Personnel (t-1) measures in the event that the null results are due to the skewed distribution of the variables and influence of outliers. However, doing so does not change the results and instead reduces the significance of the UN PK Personnel (t-1) variable. We do not include the logged version of these two variables in the main model as neither variable is highly skewed. For example, the skewedness and kurtosis are only 0.278 and -1.288 for the UN PK Budget (t-1) variable and 0.007 and -1.348 for the UN PK Personnel measure."  
round(skewness(pk_data$un.pk.budget.t_1, na.rm = TRUE), digits=3)
round(kurtosis(pk_data$un.pk.budget.t_1, na.rm = TRUE), digits=3)

round(skewness(pk_data$un.pk.personnel.t_1, na.rm = TRUE), digits=3)
round(kurtosis(pk_data$un.pk.personnel.t_1, na.rm = TRUE), digits=3)

# "Moving the number of ongoing extant operations from the minimum in our data of 7 to the maximum of 23 dramatically lowers the probability of a new authorization from 23.6% in a given year to 0.4%.  Nevertheless, if a conflict has a peace agreement in place, the likelihood of a new mission authorization to that conflict increases from 0.9% in a given year to 5.2% in a given year."
pk_data_nona<-pk_data[c("un.pk.operations.t_1","un.pk.personnel.t_1","un.pk.budget.t_1","un.pk.fatalities.t_1","peace.agreement.t_1","civil.conflict.year","total.civil.conflicts","previous.un.pk.operation","civilian.casualties.log","battle.deaths.log","population.log","armed.forces.log","democracy","p5.alliance")]
pk_data_nona<-na.omit(pk_data_nona)

new_data_ops <- with(pk_data_nona, data.frame(un.pk.operations.t_1 = c(7, 23), un.pk.personnel.t_1=mean(un.pk.personnel.t_1), un.pk.budget.t_1=mean(un.pk.budget.t_1), un.pk.fatalities.t_1=mean(un.pk.fatalities.t_1), peace.agreement.t_1=mean(peace.agreement.t_1), civil.conflict.year=mean(civil.conflict.year), total.civil.conflicts=mean(total.civil.conflicts), previous.un.pk.operation=mean(previous.un.pk.operation), civilian.casualties.log=mean(civilian.casualties.log), battle.deaths.log=mean(battle.deaths.log), population.log=mean(population.log),armed.forces.log=mean(armed.forces.log),democracy=mean(democracy),p5.alliance=mean(p5.alliance)))
round(predict(tab.1.m2, new_data_ops, type="response"), digits=3)*100

newdata_peace <- with(pk_data_nona, data.frame(peace.agreement.t_1 = c(0, 1), un.pk.personnel.t_1=mean(un.pk.personnel.t_1), un.pk.budget.t_1=mean(un.pk.budget.t_1), un.pk.fatalities.t_1=mean(un.pk.fatalities.t_1), un.pk.operations.t_1=mean(un.pk.operations.t_1), civil.conflict.year=mean(civil.conflict.year), total.civil.conflicts=mean(total.civil.conflicts), previous.un.pk.operation=mean(previous.un.pk.operation), civilian.casualties.log=mean(civilian.casualties.log), battle.deaths.log=mean(battle.deaths.log), population.log=mean(population.log),armed.forces.log=mean(armed.forces.log),democracy=mean(democracy),p5.alliance=mean(p5.alliance)))
round(predict(tab.1.m2, newdata_peace, type="response"), digits=3)*100

#########################################################################
# Table A1: Descriptive Statistics of Independent and Control Variables
#########################################################################

# N
un.pk.operations.t_1 <- pk_data[!is.na(pk_data$un.pk.operations.t_1),]
un.pk.personnel.t_1 <- pk_data[!is.na(pk_data$un.pk.personnel.t_1),]
un.pk.budget.t_1 <- pk_data[!is.na(pk_data$un.pk.budget.t_1),]
un.pk.fatalities.t_1 <- pk_data[!is.na(pk_data$un.pk.fatalities.t_1),]
peace.agreement <- pk_data[!is.na(pk_data$peace.agreement),]
civil.conflict.year <- pk_data[!is.na(pk_data$civil.conflict.year),]
total.civil.conflicts <- pk_data[!is.na(pk_data$total.civil.conflicts),]
civilian.casualties.log <- pk_data[!is.na(pk_data$civilian.casualties.log),]
battle.deaths.log <- pk_data[!is.na(pk_data$battle.deaths.log),]
population.log <- pk_data[!is.na(pk_data$population.log),]
armed.forces.log <- pk_data[!is.na(pk_data$armed.forces.log),]
democracy <- pk_data[!is.na(pk_data$democracy),]
p5.alliance <- pk_data[!is.na(pk_data$p5.alliance),]
previous.un.pk.operation <- pk_data[!is.na(pk_data$previous.un.pk.operation),]
ongoing.nonunpk.operation <- pk_data[!is.na(pk_data$ongoing.nonunpk.operation),]
n_un.pk.operations.t_1<-length(un.pk.operations.t_1$un.pk.operations.t_1)
n_un.pk.personnel.t_1<-length(un.pk.personnel.t_1$un.pk.personnel.t_1)
n_un.pk.budget.t_1<-length(un.pk.budget.t_1$un.pk.budget.t_1)
n_un.pk.fatalities.t_1<-length(un.pk.fatalities.t_1$un.pk.fatalities.t_1)
n_peace.agreement<-length(peace.agreement$peace.agreement)
n_civil.conflict.year<-length(civil.conflict.year$civil.conflict.year)
n_total.civil.conflicts<-length(total.civil.conflicts$total.civil.conflicts)
n_civilian.casualties.log<-length(civilian.casualties.log$civilian.casualties.log)
n_battle.deaths.log<-length(battle.deaths.log$battle.deaths.log)
n_population.log <- length(population.log$population.log)
n_armed.forces.log <- length(armed.forces.log$armed.forces.log)
n_democracy <- length(democracy$democracy)
n_p5.alliance <- length(p5.alliance$p5.alliance)
n_previous.un.pk.operation <- length(previous.un.pk.operation$previous.un.pk.operation)
n_ongoing.nonunpk.operation <- length(ongoing.nonunpk.operation$ongoing.nonunpk.operation)

# Standard Deviation
sd_un.pk.operations.t_1<-sd(un.pk.operations.t_1$un.pk.operations.t_1) 
sd_un.pk.personnel.t_1<-sd(un.pk.personnel.t_1$un.pk.personnel.t_1)
sd_un.pk.budget.t_1<-sd(un.pk.budget.t_1$un.pk.budget.t_1)
sd_un.pk.fatalities.t_1<-sd(un.pk.fatalities.t_1$un.pk.fatalities.t_1)
sd_peace.agreement<-sd(peace.agreement$peace.agreement)
sd_civil.conflict.year<-sd(civil.conflict.year$civil.conflict.year)
sd_total.civil.conflicts<-sd(total.civil.conflicts$total.civil.conflicts)
sd_civilian.casualties.log<-sd(civilian.casualties.log$civilian.casualties.log)
sd_battle.deaths.log<-sd(battle.deaths.log$battle.deaths.log) 
sd_population.log <- sd(population.log$population.log)
sd_armed.forces.log <- sd(armed.forces.log$armed.forces.log)
sd_democracy <- sd(democracy$democracy)
sd_p5.alliance <- sd(p5.alliance$p5.alliance)
sd_previous.un.pk.operation <- sd(previous.un.pk.operation$previous.un.pk.operation)
sd_ongoing.nonunpk.operation <- sd(ongoing.nonunpk.operation$ongoing.nonunpk.operation)

# Mean
mean_un.pk.operations.t_1<-mean(un.pk.operations.t_1$un.pk.operations.t_1) 
mean_un.pk.personnel.t_1<-mean(un.pk.personnel.t_1$un.pk.personnel.t_1)
mean_un.pk.budget.t_1<-mean(un.pk.budget.t_1$un.pk.budget.t_1)
mean_un.pk.fatalities.t_1<-mean(un.pk.fatalities.t_1$un.pk.fatalities.t_1)
mean_peace.agreement<-mean(peace.agreement$peace.agreement)
mean_civil.conflict.year<-mean(civil.conflict.year$civil.conflict.year)
mean_total.civil.conflicts<-mean(total.civil.conflicts$total.civil.conflicts)
mean_civilian.casualties.log<-mean(civilian.casualties.log$civilian.casualties.log)
mean_battle.deaths.log<-mean(battle.deaths.log$battle.deaths.log) 
mean_population.log <- mean(population.log$population.log)
mean_armed.forces.log <- mean(armed.forces.log$armed.forces.log)
mean_democracy <- mean(democracy$democracy)
mean_p5.alliance <- mean(p5.alliance$p5.alliance)
mean_previous.un.pk.operation <- mean(previous.un.pk.operation$previous.un.pk.operation)
mean_ongoing.nonunpk.operation <- mean(ongoing.nonunpk.operation$ongoing.nonunpk.operation)

# Min
min_un.pk.operations.t_1<-min(un.pk.operations.t_1$un.pk.operations.t_1) 
min_un.pk.personnel.t_1<-min(un.pk.personnel.t_1$un.pk.personnel.t_1)
min_un.pk.budget.t_1<-min(un.pk.budget.t_1$un.pk.budget.t_1)
min_un.pk.fatalities.t_1<-min(un.pk.fatalities.t_1$un.pk.fatalities.t_1)
min_peace.agreement<-min(peace.agreement$peace.agreement)
min_civil.conflict.year<-min(civil.conflict.year$civil.conflict.year)
min_total.civil.conflicts<-min(total.civil.conflicts$total.civil.conflicts)
min_civilian.casualties.log<-min(civilian.casualties.log$civilian.casualties.log)
min_battle.deaths.log<-min(battle.deaths.log$battle.deaths.log) 
min_population.log <- min(population.log$population.log)
min_armed.forces.log <- min(armed.forces.log$armed.forces.log)
min_democracy <- min(democracy$democracy)
min_p5.alliance <- min(p5.alliance$p5.alliance)
min_previous.un.pk.operation <- min(previous.un.pk.operation$previous.un.pk.operation)
min_ongoing.nonunpk.operation <- min(ongoing.nonunpk.operation$ongoing.nonunpk.operation)

# Max
max_un.pk.operations.t_1<-max(un.pk.operations.t_1$un.pk.operations.t_1) 
max_un.pk.personnel.t_1<-max(un.pk.personnel.t_1$un.pk.personnel.t_1)
max_un.pk.budget.t_1<-max(un.pk.budget.t_1$un.pk.budget.t_1)
max_un.pk.fatalities.t_1<-max(un.pk.fatalities.t_1$un.pk.fatalities.t_1)
max_peace.agreement<-max(peace.agreement$peace.agreement)
max_civil.conflict.year<-max(civil.conflict.year$civil.conflict.year)
max_total.civil.conflicts<-max(total.civil.conflicts$total.civil.conflicts)
max_civilian.casualties.log<-max(civilian.casualties.log$civilian.casualties.log)
max_battle.deaths.log<-max(battle.deaths.log$battle.deaths.log) 
max_population.log <- max(population.log$population.log)
max_armed.forces.log <- max(armed.forces.log$armed.forces.log)
max_democracy <- max(democracy$democracy)
max_p5.alliance <- max(p5.alliance$p5.alliance)
max_previous.un.pk.operation<- max(previous.un.pk.operation$previous.un.pk.operation )
max_ongoing.nonunpk.operation<- max(ongoing.nonunpk.operation$ongoing.nonunpk.operation )

# Create table
all_un.pk.operations.t_1<-cbind(n_un.pk.operations.t_1, mean_un.pk.operations.t_1, sd_un.pk.operations.t_1, min_un.pk.operations.t_1, max_un.pk.operations.t_1)
all_un.pk.personnel.t_1<-cbind(n_un.pk.personnel.t_1, mean_un.pk.personnel.t_1, sd_un.pk.personnel.t_1, min_un.pk.personnel.t_1, max_un.pk.personnel.t_1)
all_un.pk.budget.t_1<-cbind(n_un.pk.budget.t_1, mean_un.pk.budget.t_1, sd_un.pk.budget.t_1, min_un.pk.budget.t_1, max_un.pk.budget.t_1)
all_un.pk.fatalities.t_1<-cbind(n_un.pk.fatalities.t_1, mean_un.pk.fatalities.t_1, sd_un.pk.fatalities.t_1, min_un.pk.fatalities.t_1, max_un.pk.fatalities.t_1)
all_peace.agreement<-cbind(n_peace.agreement, mean_peace.agreement, sd_peace.agreement, min_peace.agreement, max_peace.agreement)
all_civil.conflict.year<-cbind(n_civil.conflict.year, mean_civil.conflict.year, sd_civil.conflict.year, min_civil.conflict.year, max_civil.conflict.year)
all_total.civil.conflicts<-cbind(n_total.civil.conflicts, mean_total.civil.conflicts, sd_total.civil.conflicts, min_total.civil.conflicts, max_total.civil.conflicts)
all_civilian.casualties.log<-cbind(n_civilian.casualties.log, mean_civilian.casualties.log, sd_civilian.casualties.log, min_civilian.casualties.log, max_civilian.casualties.log)
all_battle.deaths.log<-cbind(n_battle.deaths.log, mean_battle.deaths.log, sd_battle.deaths.log, min_battle.deaths.log, max_battle.deaths.log)
all_population.log <- cbind(n_population.log,mean_population.log,sd_population.log,min_population.log,max_population.log)
all_armed.forces.log <- cbind(n_armed.forces.log,mean_armed.forces.log,sd_armed.forces.log,min_armed.forces.log,max_armed.forces.log)
all_democracy <- cbind(n_democracy,mean_democracy,sd_democracy,min_democracy,max_democracy)
all_p5.alliance <- cbind(n_p5.alliance,mean_p5.alliance,sd_p5.alliance,min_p5.alliance,max_p5.alliance)
all_previous.un.pk.operation <- cbind(n_previous.un.pk.operation,mean_previous.un.pk.operation,sd_previous.un.pk.operation,min_previous.un.pk.operation,max_previous.un.pk.operation)
all_ongoing.nonunpk.operation <- cbind(n_ongoing.nonunpk.operation,mean_ongoing.nonunpk.operation,sd_ongoing.nonunpk.operation,min_ongoing.nonunpk.operation,max_ongoing.nonunpk.operation)

tab.a1<-rbind(all_un.pk.operations.t_1, all_un.pk.personnel.t_1, all_un.pk.budget.t_1, all_un.pk.fatalities.t_1, all_peace.agreement, all_civil.conflict.year, all_total.civil.conflicts, all_previous.un.pk.operation, all_ongoing.nonunpk.operation, all_civilian.casualties.log, all_battle.deaths.log, all_population.log,all_armed.forces.log,all_democracy,all_p5.alliance)
tab.a1<-as.data.frame(tab.a1)
names(tab.a1) <- gsub("_un.pk.operations.t_1", "", names(tab.a1))
tab.a1<-round(tab.a1, digits=2)
names<-c("un.pk.operations.t_1","un.pk.personnel.t_1","un.pk.budget.t_1","un.pk.fatalities.t_1","peace.agreement.t_1","civil.conflict.year","total.civil.conflicts","previous.un.pk.operation","ongoing.nonunpk.operation","civilian.casualties.log","battle.deaths.log","population.log","armed.forces.log","democracy","p5.alliance")
tab.a1<-cbind(names,tab.a1)
tab.a1

######################################################################################################################
# Table A2: Logistic Regression, UN authorization of peacekeeping mission, Sub-sample of civil-conflict country-years
######################################################################################################################

cw_yrs<-pk_data[pk_data$civil.conflict==1,]

# Model 1: Independent Variables Only, DV = UN PK Mission Authorized
tab.a2.m1 <- glm(un.pk.mission~un.pk.operations.t_1+ un.pk.personnel.t_1+ un.pk.budget.t_1+ un.pk.fatalities.t_1+ peace.agreement.t_1,data=cw_yrs,family=binomial)

# Model 2: Independent and Control Variables, DV = UN PK Mission Authorized
tab.a2.m2 <- glm(un.pk.mission~un.pk.operations.t_1+ un.pk.personnel.t_1+ un.pk.budget.t_1+ un.pk.fatalities.t_1+ peace.agreement.t_1+ civil.conflict.year+ total.civil.conflicts+ previous.un.pk.operation + civilian.casualties.log+ battle.deaths.log+ population.log+armed.forces.log+democracy+p5.alliance,data=cw_yrs,family=binomial)
stargazer(tab.a2.m1, tab.a2.m2, type = "text")

# Pseudo R2: McFadden
round(pR2(tab.a2.m1), digits=3)
round(pR2(tab.a2.m2), digits=3)

# LR chi2 and Prob>chi2 
round(lrtest(tab.a2.m1), digits=3)
round(lrtest(tab.a2.m2), digits=3)

######################################################################################################################
# Table A3: Logistic Regression, UN authorization of PK mission, Sub-sample of post-conflict country-years
######################################################################################################################

post_cw_yrs<-pk_data[pk_data$civil.conflict==0,]

# Model 1: Independent Variables Only, DV = UN PK Mission Authorized
tab.a3.m1 <- glm(un.pk.mission~un.pk.operations.t_1+ un.pk.personnel.t_1+ un.pk.budget.t_1+ un.pk.fatalities.t_1+ peace.agreement.t_1,data=post_cw_yrs,family=binomial)

# Model 2: Independent and Control Variables, DV = UN PK Mission Authorized
tab.a3.m2 <- glm(un.pk.mission~un.pk.operations.t_1+ un.pk.personnel.t_1+ un.pk.budget.t_1+ un.pk.fatalities.t_1+ peace.agreement.t_1+ civil.conflict.year+ total.civil.conflicts+ previous.un.pk.operation + civilian.casualties.log+ battle.deaths.log+ population.log+armed.forces.log+democracy+p5.alliance,data=post_cw_yrs,family=binomial)
stargazer(tab.a3.m1, tab.a3.m2, type = "text")

# Pseudo R2: McFadden
round(pR2(tab.a3.m1), digits=3)
round(pR2(tab.a3.m2), digits=3)

# LR chi2 and Prob>chi2 
round(lrtest(tab.a3.m1), digits=3)
round(lrtest(tab.a3.m2), digits=3)

#####################################################################################################
# Table A4: Logistic Regression, UN PK authorization, UN PK Troops in replacement of UN PK Personnel
#####################################################################################################

# Model 1: Independent Variables Only, DV = UN PK Mission Authorized
tab.a4.m1 <- glm(un.pk.mission~un.pk.operations.t_1+ un.pk.troop.personnel.t_1+ un.pk.budget.t_1+ un.pk.fatalities.t_1+ peace.agreement.t_1,data=pk_data,family=binomial)

# Model 2: Independent and Control Variables, DV = UN PK Mission Authorized
tab.a4.m2 <- glm(un.pk.mission~un.pk.operations.t_1+ un.pk.troop.personnel.t_1+ un.pk.budget.t_1+ un.pk.fatalities.t_1+ peace.agreement.t_1+ civil.conflict.year+ total.civil.conflicts+ previous.un.pk.operation + civilian.casualties.log+ battle.deaths.log+ population.log+armed.forces.log+democracy+p5.alliance,data=pk_data,family=binomial)
stargazer(tab.a4.m1, tab.a4.m2, type = "text")

# Pseudo R2: McFadden
round(pR2(tab.a4.m1), digits=3)
round(pR2(tab.a4.m2), digits=3)

# LR chi2 and Prob>chi2 
round(lrtest(tab.a4.m1), digits=3)
round(lrtest(tab.a4.m2), digits=3)

#############################################################################################################
# Table A5: Logistic Regression, UN PK authorization, UN PK Malicious fatalities in place of UN PK Fatalities
#############################################################################################################

# Model 1: Independent Variables Only, DV = UN PK Mission Authorized
tab.a5.m1 <- glm(un.pk.mission~un.pk.operations.t_1+ un.pk.personnel.t_1+ un.pk.budget.t_1+ un.pk.malicious.fatalaties.t_1+ peace.agreement.t_1,data=pk_data,family=binomial)

# Model 2: Independent and Control Variables, DV = UN PK Mission Authorized
tab.a5.m2 <- glm(un.pk.mission~un.pk.operations.t_1+ un.pk.personnel.t_1+ un.pk.budget.t_1+ un.pk.malicious.fatalaties.t_1+ peace.agreement.t_1+ civil.conflict.year+ total.civil.conflicts+ previous.un.pk.operation + civilian.casualties.log+ battle.deaths.log+ population.log+armed.forces.log+democracy+p5.alliance,data=pk_data,family=binomial)
stargazer(tab.a5.m1, tab.a5.m2, type = "text")

# Pseudo R2: McFadden
round(pR2(tab.a5.m1), digits=3)
round(pR2(tab.a5.m2), digits=3)

# LR chi2 and Prob>chi2 
round(lrtest(tab.a5.m1), digits=3)
round(lrtest(tab.a5.m2), digits=3)

###############################################################################################
# Table A6: Logistic Regression, UN authorization of peacekeeping mission, Interactive Effects
###############################################################################################

pk_data$civilian.casualties.categ = factor(pk_data$civilian.casualties.categ,levels(pk_data$civilian.casualties.categ)[c(2,3,1)])

# Model 3: Interactive Effect UN PK Operations, DV = UN PK Mission Authorized
tab.a6.m3 <- glm(un.pk.mission~un.pk.operations.t_1+ un.pk.personnel.t_1+ un.pk.budget.t_1+ un.pk.fatalities.t_1+ peace.agreement.t_1+civilian.casualties.categ+un.pk.operations.t_1*civilian.casualties.categ + civil.conflict.year+ total.civil.conflicts+ previous.un.pk.operation + battle.deaths.log+ population.log+armed.forces.log+democracy+p5.alliance,data=pk_data,family=binomial)

# Model 4: Interactive Effect UN PK Personnel, DV = UN PK Mission Authorized
tab.a6.m4 <- glm(un.pk.mission~un.pk.operations.t_1+ un.pk.personnel.t_1+ un.pk.budget.t_1+ un.pk.fatalities.t_1+ peace.agreement.t_1+civilian.casualties.categ+un.pk.personnel.t_1*civilian.casualties.categ + civil.conflict.year+ total.civil.conflicts+ previous.un.pk.operation + battle.deaths.log+ population.log+armed.forces.log+democracy+p5.alliance,data=pk_data,family=binomial)

# Model 5: Interactive Effect UN PK Budget, DV = UN PK Mission Authorized
tab.a6.m5 <- glm(un.pk.mission~un.pk.operations.t_1+ un.pk.personnel.t_1+ un.pk.budget.t_1+ un.pk.fatalities.t_1+ peace.agreement.t_1+civilian.casualties.categ+un.pk.budget.t_1*civilian.casualties.categ + civil.conflict.year+ total.civil.conflicts+ previous.un.pk.operation + battle.deaths.log+ population.log+armed.forces.log+democracy+p5.alliance,data=pk_data,family=binomial)

# Model 6: Interactive Effect UN PK Fatalities, DV = UN PK Mission Authorized
tab.a6.m6 <- glm(un.pk.mission~un.pk.operations.t_1+ un.pk.personnel.t_1+ un.pk.budget.t_1+ un.pk.fatalities.t_1+ peace.agreement.t_1+civilian.casualties.categ+un.pk.fatalities.t_1*civilian.casualties.categ + civil.conflict.year+ total.civil.conflicts+ previous.un.pk.operation + battle.deaths.log+ population.log+armed.forces.log+democracy+p5.alliance,data=pk_data,family=binomial)

# Model 7: Interactive Effect Peace Agreement, DV = UN PK Mission Authorized
tab.a6.m7 <- glm(un.pk.mission~un.pk.operations.t_1+ un.pk.personnel.t_1+ un.pk.budget.t_1+ un.pk.fatalities.t_1+ peace.agreement.t_1+civilian.casualties.categ+peace.agreement.t_1*civilian.casualties.categ + civil.conflict.year+ total.civil.conflicts+ previous.un.pk.operation + battle.deaths.log+ population.log+armed.forces.log+democracy+p5.alliance,data=pk_data,family=binomial)
stargazer(tab.a6.m3,tab.a6.m4,tab.a6.m5,tab.a6.m6,tab.a6.m7, type = "text", order=c(1,2,3,4,5,6,7,16,17,18,19,20,21,22,23,24,25,8,9,10,11,12,13,14,15,26))

# Pseudo R2: McFadden
round(pR2(tab.a6.m3), digits=3)
round(pR2(tab.a6.m4), digits=3)
round(pR2(tab.a6.m5), digits=3)
round(pR2(tab.a6.m6), digits=3)
round(pR2(tab.a6.m7), digits=3)

# LR chi2 and Prob>chi2 
round(lrtest(tab.a6.m3), digits=3)
round(lrtest(tab.a6.m4), digits=3)
round(lrtest(tab.a6.m5), digits=3)
round(lrtest(tab.a6.m6), digits=3)
round(lrtest(tab.a6.m7), digits=3)

#######################################################################
# Table A7.  Authorization of Regional and Multinational PK Operations
#######################################################################

# Model 1: Independent Variables Only, DV = Regional/Multinational PK Mission Authorized
tab.a7.m1 <- glm(nonun.pk.mission~un.pk.operations.t_1+ un.pk.personnel.t_1+ un.pk.budget.t_1+ un.pk.fatalities.t_1+ peace.agreement.t_1,data=pk_data,family=binomial)

# Model 2: Independent and Control Variables, DV = Regional/Multinational PK Mission Authorized
tab.a7.m2 <- glm(nonun.pk.mission~un.pk.operations.t_1+ un.pk.personnel.t_1+ un.pk.budget.t_1+ un.pk.fatalities.t_1+ peace.agreement.t_1+ civil.conflict.year+ total.civil.conflicts+ previous.un.pk.operation + civilian.casualties.log+ battle.deaths.log+ population.log+armed.forces.log+democracy+p5.alliance,data=pk_data,family=binomial)
stargazer(tab.a7.m1, tab.a7.m2, type = "text")

# Pseudo R2: McFadden
round(pR2(tab.a7.m1), digits=3)
round(pR2(tab.a7.m2), digits=3)

# LR chi2 and Prob>chi2 
round(lrtest(tab.a7.m1), digits=3)
round(lrtest(tab.a7.m2), digits=3)

###################################################################################
# Table A8. UN Authorization Controlling for Ongoing Regional/Multinational Mission
###################################################################################

# Model 1: Independent Variables Only, DV = UN PK Mission Authorized
tab.a8.m1 <- glm(un.pk.mission~un.pk.operations.t_1+ un.pk.personnel.t_1+ un.pk.budget.t_1+ un.pk.fatalities.t_1+ peace.agreement.t_1,data=pk_data,family=binomial)

# Model 2: Independent and Control Variables, DV = UN PK Mission Authorized
tab.a8.m2 <- glm(un.pk.mission~un.pk.operations.t_1+ un.pk.personnel.t_1+ un.pk.budget.t_1+ un.pk.fatalities.t_1+ peace.agreement.t_1+ civil.conflict.year+ total.civil.conflicts+ previous.un.pk.operation + ongoing.nonunpk.operation + civilian.casualties.log+ battle.deaths.log+ population.log+armed.forces.log+democracy+p5.alliance,data=pk_data,family=binomial)
stargazer(tab.a8.m1, tab.a8.m2, type = "text")

# Pseudo R2: McFadden
round(pR2(tab.a8.m1), digits=3)
round(pR2(tab.a8.m2), digits=3)

# LR chi2 and Prob>chi2 
round(lrtest(tab.a8.m1), digits=3)
round(lrtest(tab.a8.m2), digits=3)

##############################################################
# Figure A1: Number of UN Peacekeeping Authorizations, by year
##############################################################

pk_ops<-pk_data[pk_data$un.pk.mission==1,]
fig.a1 <- ggplot(pk_ops, aes(as.factor(year)))
fig.a1 + geom_bar() + labs(x = "Year", y ="UN Peacekeeping Authorizations") + theme_classic()

################################################################
# Figure A2: Number of UN Peacekeeping Operations (t-1), by year
################################################################

pk_t_1<-pk_data[!duplicated(pk_data$year),]
fig.a2 <- ggplot(pk_t_1, aes(x=as.factor(year), y=as.factor(un.pk.operations.t_1)))
fig.a2 + geom_bar(stat="identity") + labs(x = "Year", y ="UN Peacekeeping Operations (t-1)") + theme_classic()

########################################################################
# Figure A3: Number of UN Peacekeeping Personnel Deployed (t-1), by year
########################################################################

pk_t_1_person<-pk_t_1[pk_t_1$year>1990,]
fig.a3 <- ggplot(pk_t_1_person, aes(x=as.factor(year), y=un.pk.personnel.t_1))
fig.a3 + geom_bar(stat="identity") + labs(x = "Year", y ="UN Peacekeeping Personnel (t-1)") + theme_classic() + scale_y_continuous(name = "UN Peacekeeping Personnel (t-1)", breaks = seq(0, 1269604, by = 100000), limits = c(0, 1269604))

##############################################################
# Figure A4: UN Peacekeeping Expenditure in USD (t-1), by year
##############################################################

fig.a4 <- ggplot(pk_t_1, aes(x=as.factor(year), y=un.pk.budget.t_1))
fig.a4 + geom_bar(stat="identity") + labs(x = "Year", y ="UN Peacekeeping Budget (t-1)") + theme_classic()

#################################################################
# Figure A5: Number of UN Peacekeeping Fatalities (t-1), by year
#################################################################

fig.a5 <- ggplot(pk_t_1, aes(x=as.factor(year), y=as.factor(un.pk.fatalities.t_1)))
fig.a5 + geom_bar(stat="identity") + labs(x = "Year", y ="UN Peacekeeping Fatalities (t-1)") + theme_classic()
